put reWrap(cd field "Strung Text", lineLength) into cd field "Unstrung Text"
unlock screen
set cursor to 1
end mouseUp
function reWrap textIn, lineLength
--
-- Set starting values ...
--
put 1 into startChar
put the length of textIn into numChars
if numChars < lineLength then
put numChars into lineLength
end if
put lineLength into endChar
put empty into textOut
put 1 into showLine
--
-- The main processing loop ...
--
repeat
put "Working on line" && showLine && "of the reWrapped text ..." into msg
put char startChar to endChar of textIn into testString
--
-- Respect existing Returns in the text ...
--
put offset(return,testString) into returnLoc
if returnLoc ≠ 0 then
put (startChar + (returnLoc - 1)) into endChar
else
if endChar ≠ numChars then
--
-- Back up till we find a space
--
repeat until char endChar of textIn = " "
subtract 1 from endChar
--
-- Let's make sure we don't box ourselves in ...
--
if endChar ‚â§ startChar then
put ((startChar + the number of chars in testString) - 1) into endChar
exit repeat
end if
end repeat
end if
end if
put char startChar to endChar of textIn after textOut
add 1 to showLine
if endChar = numChars then
exit repeat
end if
--
-- We don't need to add a Return if we've already got one
--
if returnLoc = 0 then
put return after textOut
end if
--
-- Increment Start and End positions for the next go-round
--
put (endChar + 1) into startChar
if (numChars - endChar) < lineLength then
put numChars into endChar
else
add lineLength to endChar
end if
end repeat
hide msg
return textOut
end reWrap
-- part 4 (field)
-- low flags: 81
-- high flags: 2002
-- rect: left=18 top=31 right=332 bottom=395
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Notes
-- part 5 (button)
-- low flags: 00
-- high flags: A000
-- rect: left=430 top=42 right=91 bottom=478
-- title width / last selected line: 0
-- icon id / first selected line: 2478 / 2478
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Notes
----- HyperTalk script -----
on mouseUp
if the short name of me is "Notes" then
show cd field "Notes"
set the name of me to "Hide"
else
hide cd field "Notes"
set the name of me to "Notes"
end if
end mouseUp
-- part contents for card part 1
----- text -----
Poor soul, the centre of our sinful earth; thrall to these rebel powers that thee array; why dost thou pine within and suffer dearth, painting thy outward walls so costly gay? Why so large cost, having so short a lease, dost thou upon thy fading mansion spend?
Shall worms, inheritors of this excess, eat up thy charge? Is this thy body's end?
Then, soul, live thou upon thy servant's loss, and let that pine to aggravate thy store. Buy terms divine in selling hours of dross. Within be fed; without be rich no more.
So shalt thou feed on death, that feeds on men; and death once dead, there's no more dying then.
-- part contents for card part 4
----- text -----
ReWrap illustrates a function that takes a text field and adjusts the word wrap to a specified line length. It puts in Return characters as needed to maintain the line length.
The parameters are the text field you want to rewrap and the length you want to adjust it to.
The result is in It.
Mainly a HyperTalk experiment; the speed of the operation leaves something to be desired.
-- Tad Davis, CompuServe ID 72320,3220
GEnie ID TAD.DAVIS
The text, by the way, is Sonnet 146 by William Shakespeare.